
MyDesktop.TeamSettings = Ext.extend(Ext.app.Module, {
    init : function(){
        this.launcher = {
            text: _('Team Settings'),
            iconCls:'settings',
            handler : this.createWindow,
            scope: this,
            windowId: 'teamsettings'
        }
    },
	
    createWindow : function(src){
        var desktop = this.app.getDesktop();
        var winname = src.windowId;
        var win = desktop.getWindow(winname);

        if(!win){
			var statusBar;
			
        	var prefPanel = new Ext.ux.JsonPanel({autoLoad: getMainUrl('action=team_preferences'),msg: _('Loading...')}); 

		    var prefForm = new Ext.form.FormPanel({
		        url: getMainUrl(),
		        labelAlign: 'top',
		        baseParams: {action: 'team_preferences', op: 'save'},
		        items: prefPanel,
		        waitMsgTarget: true,
		        frame: true,
	        	height: 340,
				tbar: [{
					text: _('Save'),
					tooltip: _('Save'),
					iconCls: 'save',
					handler: function() {
		                	prefForm.initFields();
		                	var valid = true;
		                	if (prefForm.findById('autoreply').getValue()==true && prefForm.findById('replymsg').getValue()=="") {
		                		prefForm.findById('replymsg').markInvalid();
		                		valid = false;
		                	}
		                	if (prefForm.findById('rplheader').getValue()==true && prefForm.findById('rplheadermsg').getValue()=="") {
		                		prefForm.findById('rplheadermsg').markInvalid();
		                		valid = false;
		                	}
                    		if (valid) {
	                    		prefForm.getForm().submit({ 
		                        	method:'POST', 
		                        	waitTitle: _('Saving...'), 
		                        	waitMsg: _('Saving...'),
		
			                        success:function(form, action){
			                        	win.close();
			                        }                     	
	                    		});
                    		}
                    	}
				}]		        	
			});        	

            win = desktop.createWindow({
                id: winname,
                title:src.text,
                width:420,
                height:365,
                resizable: false,
                maximizable: false,
                iconCls: 'settings',
                items: prefForm
            });
            
        }
        win.show();
        
    }
});